how to ingetration paytm in codeignter 3 - deesoft service

how to ingetration paytm in codeignter 3

Deepak Tailor Image
Deepak Tailor - Feb 05 2023
how to ingetration paytm in codeignter 3

Sure, here are the steps to integrate the Paytm payment gateway in CodeIgniter 3:

Here is an example of how you can integrate Paytm into CodeIgniter 3:

Download and extract the Paytm library for PHP from the Paytm website.

Create a new folder "libraries" in the "application" folder of your CodeIgniter installation and copy the extracted Paytm library files into it.

Create a new library file in the "libraries" folder, for example "Paytm.php", with the following code:

defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . 'libraries/Paytm/PaytmWallet.php';

use PaytmWallet;

class Paytm {
    
    public function __construct() {
        $this->_ci =& get_instance();
        $this->_ci->config->load('paytm',TRUE);
        $this->paytm_config = $this->_ci->config->item('paytm');
        $this->paytm = new PaytmWallet($this->paytm_config);
    }
    
    public function paytm_txn_status($order_id, $request) {
        return $this->paytm->status($order_id, $request);
    }
    
    public function paytm_txn_request($order, $params) {
        return $this->paytm->initiateTransaction($order, $params);
    }
    
}

Create a new config file in the "config" folder, for example "paytm.php", with the following code:

defined('BASEPATH') OR exit('No direct script access allowed');

$config['paytm_merchant_id'] = "YOUR_PAYTM_MERCHANT_ID";
$config['paytm_merchant_key'] = "YOUR_PAYTM_MERCHANT_KEY";
$config['paytm_merchant_website'] = "YOUR_PAYTM_MERCHANT_WEBSITE";
$config['paytm_industry_type'] = "YOUR_PAYTM_INDUSTRY_TYPE";
$config['paytm_channel'] = "YOUR_PAYTM_CHANNEL";
$config['paytm_transaction_url'] = "https://securegw.paytm.in/theia/processTransaction";
$config['paytm_status_query_url'] = "https://securegw.paytm.in/merchant-status/getTxnStatus";
$config['paytm_refund_url'] = "https://securegw.paytm.in/refund/apply";
$config['paytm_callback_url'] = "YOUR_CALLBACK_URL";

Load the Paytm library in your controller where you want to integrate it:

$this->load->library('paytm');

Use the methods of the Paytm library in your controller to initiate transactions and get transaction status:

$order = array(
    'order_id' => 'ORDER_ID_' . time(),
    'amount' => 'AMOUNT_IN_PAYTM_WALLET',
    'email' => 'CUSTOMER_EMAIL',
    'mobile_number' => 'CUSTOMER_MOBILE_NUMBER',
);

$params = array(
    'request_type' => 'DEFAULT',
);

$paytm_txn_request = $this->paytm->paytm_txn_request($order, $params);

After getting the transaction request, redirect the customer to the Paytm payment page using the following code:

if($paytm_txn_request['STATUS'] === 'TXN_SUCCESS') {
    $this->paytm->paytm_txn_request['paytm_txn_url'] = $paytm_txn_request['paytm_txn_url'];
    $this->load->view('paytm_redirect', $paytm_txn_request);
} else {
    // handle error response
}

Create a new view file "paytm_redirect.php" in the "views" folder with the following code:

<html>
<head>
    <title>Paytm Payment Gateway</title>
</head>
<body onload="document.paytm_form.submit();">
    <h2>Please wait, your transaction is being processed...</h2>
    <form method="post" action="<?php echo $paytm_txn_url; ?>" name="paytm_form">
        <table border="1">
            <tbody>
                <?php foreach($paytm_txn_request as $name => $value) { ?>
                <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>">
                <?php } ?>
            </tbody>
        </table>
    </form>
</body>
</html>

After the customer completes the payment on the Paytm payment page, Paytm will send a response to the callback URL. You can handle this response in the callback function to get the transaction status and update your database accordingly.

public function paytm_callback() {
    $order_id = $this->input->get('ORDERID');
    $request = $_REQUEST;
    $paytm_txn_status = $this->paytm->paytm_txn_status($order_id, $request);
    if($paytm_txn_status['STATUS'] === 'TXN_SUCCESS') {
        // update database and show success message
    } else {
        // update database and show failure message
    }
}
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in